<?php
	include_once('kiwee.class.php');
	include_once('../../../manager/includes/controls/datagrid.class.php');
	include_once('../../../manager/includes/lang/english.inc.php');
	include_once('dbconfig.inc.php');

	$kiwee = new Kiwee();	

	if ($_POST['trxntype']=="additemtocart"){
		echo $kiwee->addToCart($_POST['itemid'],$_POST['sessionid'],$_POST['opts'], $_POST['qty']);
	} else if ($_POST['trxntype']=="deletefromcart"){
		echo $kiwee->deleteItem($_POST['sessionid'], $_POST['detailid']);
	} else if ($_POST['trxntype']=="googlecart"){
		echo $kiwee->googleCheckout($_POST['sessionid']);
	} else if ($_POST['trxntype']=="paypalcart"){
		echo $kiwee->paypalCheckout($_POST['sessionid']);
	} else if ($_POST['trxntype']=="processcheckout"){
		echo $kiwee->processCheckout($_POST['sessionid'], $_POST['paymethod'], $_POST['cardtype'], $_POST['nameoncard'], $_POST['cardnum'], $_POST['routenum'], $_POST['cvvcode'], $_POST['expmo'], $_POST['expyr']);
	} else if ($_POST['trxntype']=="checkusername"){
		echo $kiwee->checkUsername($_POST['username']);
	} else if ($_POST['trxntype']=="checkemail"){
		echo $kiwee->checkEmail($_POST['email']);
	} else if ($_POST['trxntype']=="createuseraccount"){
		echo $kiwee->createUserAccount($_POST['sessionid'], $_POST['email'], $_POST['fname'], $_POST['lname'], $_POST['addr1'], $_POST['addr2'], $_POST['city'], $_POST['state'], $_POST['zip'], $_POST['country'], $_POST['phone'], $_POST['ext'], $_POST['fax'], $_POST['company'], $_POST['username'], $_POST['password']);
	} else if ($_POST['trxntype']=="updatecartgrid"){
		echo '<style type="text/css">';
		
		echo '.grid {';
		echo '    width: 100%;';
		echo '    background-color: #fff;';
		echo '    border: 1px solid silver;}';

		echo '.gridHeader {';
		echo '    color: #fff;';
		echo '    font-weight: bold;';
		echo '    background-color: #2095B2;'; // was 8FC70C 14D0FF
		echo '    height: 25px;';
		echo '    border: 1px solid #177084; }'; // was 006400 2B75FF 0400FF

		echo '.gridItem {';
		echo '    background-color: #fff;';
		echo '    padding: 3px; }';

		echo '.gridAltItem {';
		echo '    background-color: #eeeeee;';
		echo '    padding: 3px; }';

		echo '.gridRowIcon:hover {';
		echo '    background-color: #f5f5dc;'; // was f5f5dc
		echo '}';

		echo '</style>';
		echo '<br />';

		$sessionid = $_POST['sessionid'];
	    $res = mysql_query('SELECT id from ' . $kiwee->config['fpx'] . 'cart_header where session_id="' . $_POST['sessionid'] . '"') or die ("MYSQL1" . mysql_error());
	    $hid = mysql_fetch_row($res);
		echo '<input type="hidden" id="sessionid" value="' . $sessionid . '" />';
        $sql = 'Select A.id, A.totalprice, item_id, name, amount, quantity, options, optionsprice from ' . $kiwee->config['fpx'] . 'cart_detail as A INNER JOIN ' . $kiwee->config['fpx'] . 'items as B on A.item_id=B.id where header_id=' . $hid[0];
        $ds = mysql_query($sql) or die ("MYSQLTEST: " . mysql_error());

		$grd = new DataGrid('',$ds, $number_of_results);

		$grd->noRecordMsg = "No Items in Cart";

		$grd->cssClass="grid";

		$grd->columnHeaderClass="gridHeader";

		$grd->itemClass="gridItem";
 
        $grd->altItemClass="gridAltItem";

		$grd->fields="item_id, name, totalprice, quantity";

		$grd->columns= "SKU, Name, Total, Qty, Delete"; 

		$grd->colWidths="50,300,50,65,65,65";

		$grd->colAligns="left, left, center,center";

		$grd->colTypes=",template:<strong>[+name+]</strong><br /><br />Unit Price:&nbsp;&nbsp;[+amount+]<br />Options Price:&nbsp;&nbsp;[+optionsprice+]<br /><br />[+options+],currency,,template:<input class=\"itema_deleteitem_button\" type=\"button\" value=\"Delete\" onClick=\"deletefromcart([+id+]);\" name=\"deleteitems\">";

		if($listmode=='1') $grd->pageSize=0;

		if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
		echo '<input type="hidden" name="id" value="$id" />';
		echo '<input type="hidden" id="sessionid" value="' . session_id() . '" />';

		echo '<input type="hidden" name="listmode" value="' . $listmode . '" />';

		echo '<input type="hidden" name="op" value="" />';
		echo $grd->render();
	} else if ($_POST['trxntype']=="checklogin"){
		echo $kiwee->checkLogin($_POST['sessionid'], $_POST['webShortname'], $_POST['webInternalKey'], $_POST['webEmail'], $_POST['webValid'], $_POST['webUser']);
	} else if ($_POST['trxntype']=="updatecartforcheckout"){
		echo $kiwee->updateCartForCheckout($_POST['sessionid'], $_POST['emailbilling'], $_POST['fnamebilling'], $_POST['lnamebilling'], $_POST['addr1billing'], $_POST['addr2billing'], $_POST['citybilling'], $_POST['statebilling'], $_POST['zipbilling'], $_POST['phonebilling'], $_POST['extbilling'], $_POST['faxbilling'], $_POST['companybilling'], $_POST['companyship'], $_POST['fnameship'], $_POST['lnameship'], $_POST['addr1ship'], $_POST['addr2ship'], $_POST['cityship'], $_POST['stateship'], $_POST['zipship'], $_POST['phoneship'], $_POST['extship']);
 	} else if ($_POST['trxntype']=="getloginform"){
		echo "    <script type=\"text/JavaScript\">

        function getElementById(id){
            var o, d=document;
            if (d.layers) {o=d.layers[id];if(o) o.style=o};
            if (!o && d.getElementById) o=d.getElementById(id);
            if (!o && d.all) o = d.all[id];
            return o;
        }
    
        function webLoginShowForm(i){
            var a = getElementById('WebLoginLayer0');
            var b = getElementById('WebLoginLayer2');
            if(i==1 && a && b) {
                a.style.display=\"block\";
                b.style.display=\"none\";
                document.forms['loginreminder'].txtpwdrem.value = 0;
            }
            else if(i==2 && a && b) {
                a.style.display=\"none\";
                b.style.display=\"block\";    
                document.forms['loginreminder'].txtpwdrem.value = 1;
            }
        };        
        function webLoginCheckRemember () {
            if(document.loginfrm.rememberme.value==1) {
                document.loginfrm.rememberme.value=0;    
            } else {
                document.loginfrm.rememberme.value=1;
            }
        }
        function webLoginEnter(nextfield,event) {
            if(event && event.keyCode == 13) {
                if(nextfield.name=='cmdweblogin') {
                    document.loginfrm.submit();
                    return false; 
                }
                else {
                    nextfield.focus();
                    return false; 
                }
            } else {
                return true;
            }
        }
    </script>
 		<div id=\"loginform\">
		<input type=\"hidden\" value=\"0\" name=\"rememberme\" /> 
		<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		<tr>
		<td>
		      <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		        <tr>
		          <td style=\"color: white; font-size:14px;\"><b>User:</b></td>
		          <td><input id=\"usernamefield\" type=\"text\" name=\"username\" tabindex=\"1\"  onkeypress=\"return webLoginEnter(document.loginfrm.password);\" size=\"8\" style=\"width: 150px;\" value=\"\" /></td>
		        </tr>
			<tr>
			<td><br /></td>
			</tr>
		        <tr>
		          <td style=\"color: white; font-size:14px;\"><b>Password:</b></td>
		          <td><input id=\"passwordfield\" type=\"password\" name=\"password\" tabindex=\"2\" onkeypress=\"return webLoginEnter(document.loginfrm.cmdweblogin);\" style=\"width: 150px;\" value=\"\" /></td>
		  
		        </tr>
		        <tr>
		          <td><label for=\"chkbox\" style=\"cursor:pointer; color: white; font-size: 12px;\">Remember me:&nbsp; </label></td>
		          <td>
		          <table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		            <tr>
		              <td valign=\"top\"><input type=\"checkbox\" id=\"chkbox\" name=\"chkbox\" tabindex=\"4\" size=\"1\" value=\"\"  onclick=\"webLoginCheckRemember()\" /></td>
		              <td align=\"right\">                                    
		              <input type=\"button\" value=\"Login\" name=\"nameofbutton\" onClick=\"webLogin();\" /></td>
		  
		            </tr>
		          </table>
		          </td>
		        </tr>
			   <tr>
			   <td><br /></td>
			   </tr>
		        <tr>
		          <td colspan=\"2\"><a href=\"#\" style=\"font-size: 12px; color: white;\" onclick=\"getPasswordForm();\">Forget Password?</a></td>
		        </tr>
		      </table>
		  
		      </td>
		      </tr>
		      </table>
              <br />
              <input type=\"button\" value=\"Cancel\" name=\"cmdcancel\" onclick=\"hideBox();\" />	
		      </div>
			  </div>
			  
			  <div id=\"passwordreminderform\" style='position:relative;display:none'>
		      <!-- Password reminder form section -->
		      <form name=\"loginreminder\" method=\"post\" action=\"/index.php?id=4005\" style=\"margin: 0px; padding: 0px;\">
		      <input type=\"hidden\" name=\"txtpwdrem\" value=\"0\" />
		      <table border=\"0\">
		  
		          <tr>
		            <td style=\"color: white; font-size: 12px;\">Enter the email address of your account <br />below to receive your password:</td>
		          </tr>
		          <tr>
		            <td><input style=\"margin-left: 15%;\" type=\"text\" name=\"txtwebemail\" size=\"24\" /></td>
		          </tr>
		          <tr>
		            <td align=\"right\"><input type=\"submit\" value=\"Submit\" name=\"cmdweblogin\" />
		  
		            <input type=\"reset\" value=\"Cancel\" name=\"cmdcancel\" onclick=\"getLoginForm();\" /></td>
		          </tr>
		        </table>
		      </form>
		      </div>    <script type=\"text/javascript\">
		          if (document.loginfrm) document.loginfrm.username.focus();
		    </script>
		  
		  </p>
		  <p>
		  &nbsp;
		</p>
		   </div>";
	}
?>
